package com.example.my.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.my.entity.RolePermission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;


@Mapper
public interface RolePermissionMapper extends BaseMapper<RolePermission> {

    @Delete("DELETE FROM role_permission WHERE role_id = #{roleId}")
    void deleteByRoleId(@Param("roleId") Long roleId);


    @Insert({
            "<script>",
            "INSERT INTO role_permission (role_id, perm_id) VALUES ",
            "<foreach collection='pIds' item='pid' separator=','>",
            "(#{roleId}, #{pid})",
            "</foreach>",
            "</script>"
    })
    void insertBatch(@Param("roleId") Long roleId, @Param("pIds") List<Long> pIds);
}